package com.aaa.controller.mht;

import cn.hutool.core.util.ObjectUtil;
import com.aaa.aspect.LogMonitor;
import com.aaa.controller.BaseController;
import com.aaa.entity.PageSortEntity;
import com.aaa.entity.Result;
import com.aaa.entity.fpa.TestPlanFpa;
import com.aaa.entity.mht.TestPlanMht;
import com.aaa.entity.systemmanage.Role;
import com.aaa.entity.systemmanage.User;
import com.aaa.service.mht.TestPlanMhtService;
import com.aaa.utils.RandomSixNumber;
import com.github.pagehelper.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 测试计划fpa(TestPlanMht)表控制层
 *
 * @author makejava
 * @since 2022-08-31 19:51:57
 */
@RestController
@RequestMapping("/testPlanMht")
public class TestPlanMhtController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private TestPlanMhtService testPlanMhtService;

    //查询所有
    @RequestMapping(method = RequestMethod.GET, value = "/queryAll.do")
    public Result queryAll(PageSortEntity pageSortEntity, TestPlanMht testPlanMht) {
        Page page = testPlanMhtService.queryAll(pageSortEntity, testPlanMht);
        return success(page.getResult(), page.getTotal());
    }

    //添加
    @LogMonitor
    @RequestMapping(method = RequestMethod.POST, value = "/insert.do")
    public Result insert(TestPlanMht testPlanMht) {
        boolean user2 = testPlanMhtService.insert(testPlanMht);
        if (user2) {
            return success();
        } else {
            return fail();
        }
    }

    //删除
    @LogMonitor
    @RequestMapping("/delete.do")
    public Result delete(String[] ids) {
        List list = new ArrayList();
        for (String id : ids) {
            list.add(id);
        }
        boolean user1 = testPlanMhtService.delete(list);
        if (true) {
            return success();
        } else {
            return fail();
        }
    }

    //修改
    @LogMonitor
    @RequestMapping("/update.do")
    public Result update(TestPlanMht testPlanMht) {
        boolean user2 = testPlanMhtService.update(testPlanMht);
        if (true) {
            return success();
        } else {
            return fail();
        }
    }


    //问题校验重名
    @GetMapping("repetitionName.do")
    public Result repetitionName(TestPlanMht testPlanMht) {
        if (ObjectUtil.isNotEmpty(testPlanMht.getTestName())) {
            boolean b = this.testPlanMhtService.repetitionName(testPlanMht);
            if (b) {
                return success("问题可用");
            } else {
                return fail("问题重复，不可用");
            }
        }
        return fail("不能为空哦！");
    }


}

